﻿using System;
using NDBGen.Descriptors.Columns.DataTypes;

namespace NDBGen.Plugins.Descriptors.Columns.DataTypes
{
    [ColumnDataTypeScriptSnippetGenerator(typeof(RowVersionDataTypeDescriptor))]
    public sealed class SqlServerRowVersionDataTypeScriptGenerator : SqlServerScriptSnippetGeneratorBase<IColumnDataTypeDescriptor>, IColumnDataTypeScriptSnippetGenerator
    {
        private const String SQL_FORMAT = "[{0}] timestamp";

        private String SqlDeclaration { get; set; }

        protected override void Init(IPluginData pluginData, IColumnDataTypeDescriptor descriptor)
        {
            base.Init(pluginData, descriptor);

            this.SqlDeclaration = String.Format(SQL_FORMAT, this.Descriptor.Column.Name);
        }

        void IColumnDataTypeScriptSnippetGenerator.WriteSql(IIndentedTextWriter writer)
        {
            writer.Write(this.SqlDeclaration);
        }
    }
}